import urllib.request
import requests
from bs4 import BeautifulSoup
import os
import sys

def  getlist(url, list_fout, confOrJour):
    res = requests.get(url)
    soup = BeautifulSoup(res.content,'html.parser')

    if confOrJour=="conf":
        soup2=soup.find_all('li', {"class": "entry inproceedings"})
    elif confOrJour=="jour":
        soup2=soup.find_all('li', {"class": "entry article"})
    else:
        print("invalid" +confOrJourl+' paper list url')
        return
    j = 1
    fp = open(list_fout, 'w')
    for i in soup2:
        s =i.find('a')['href']+'\n'
        print(s)
        fp.write(s)
        j = j+1
    fp.close()
    return j

if __name__ == '__main__':
    #e.g.: url = 'https://dblp.uni-trier.de/db/conf/icse/icse2018.html'
    url=sys.argv[1]
    list_fout=sys.argv[2]
    confOrJour=sys.argv[3]
    print('total:',getlist(url,list_fout,confOrJour))
